package com.android.application;

import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	private static final String TAG = "AutoCompleteText";
	private AutoCompleteTextView autoText;
	private TextView listText;
	private ArrayList<String> listStr = new ArrayList<String>();
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // AutoCompleteTextView
        autoText = (AutoCompleteTextView)findViewById(R.id.autoText);
        ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
        		android.R.layout.simple_dropdown_item_1line,
        		new String[] {"English", "Hebrew", "Hindi", "Spanish", "German","Greek" });
        autoText.setAdapter(aa);
        
        // Append Button
        ImageButton btn = (ImageButton)findViewById(R.id.btnAppend);
        btn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d(TAG, "Append button Clicked!");
				
				String str = autoText.getText().toString().trim();
				
				Log.d(TAG, str + " is Append!");
				
				listStr.add(str);
				
				int size = listStr.size();
				StringBuffer buffer = new StringBuffer();
				
				for(int i = 0; i < size; i++) {
					buffer.append(listStr.get(i) + "\n");
				}
				
				Log.d(TAG, buffer.toString());
				
				listText.setText(buffer.toString());
				
				buffer = null;
				
				autoText.setText("");
			}
		});
       
        btn = (ImageButton)findViewById(R.id.btnDelete);
        btn.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d(TAG, "Delete button Clicked!");
				
				listStr.clear();
				listText.setText("");
			}
		});
        
        // Initialize TextView
        listText = (TextView)findViewById(R.id.listText);
    }
}